import { createRouter, createWebHistory } from 'vue-router';
import Layout from '../layout/Layout.vue';
import { ElMessage } from 'element-plus';

const routes = [
  {
    path: '/whiteBoard',
    name: '白板',
    component: () => import("@/components/WhiteBoard/WhiteBoard.vue")
  },
  {
    path: '/',
    name: 'Layout',
    component: Layout,
    redirect: "/home", //重定向到home页面
    children: [
      {
        path: 'home',
        name: 'Home',
        component: () => import("@/views/Home"),
      }, {
        path: 'caseStatistics',
        name: 'CaseStatistics',
        component: () => import("@/views/statistics/CaseStatistics.vue"),
      }, {
        path: 'documentStatistics',
        name: 'DocumentStatistics',
        component: () => import("@/views/statistics/DocumentStatistics.vue"),
      }, {
        path: 'case',
        name: 'CaseInfo',
        component: () => import("@/views/case/CaseInfo.vue"),
      }, {
        path: 'caseApprovalNoPass',
        name: 'CaseApprovalNoPass',
        component: () => import("@/views/caseApproval/CaseApprovalNoPass.vue"),
      }, {
        path: 'caseNoApproval',
        name: 'CaseNoApproval',
        component: () => import("@/views/caseApproval/CaseNoApproval.vue"),
      }, {
        path: 'caseArchive',
        name: 'CaseArchive',
        component: () => import("@/views/caseArchive/CaseArchive.vue"),
      }, {
        path: 'caseAuditorNoPass',
        name: 'CaseAuditorNoPass',
        component: () => import("@/views/caseAuditor/CaseAuditorNoPass.vue"),
      }, {
        path: 'caseNoAuditor',
        name: 'CaseNoAuditor',
        component: () => import("@/views/caseAuditor/CaseNoAuditor.vue"),
      }, {
        path: 'caseNoCheck',
        name: 'CaseNoCheck',
        component: () => import("@/views/caseCheck/CaseNoCheck.vue"),
      }, {
        path: 'caseCheckNoPass',
        name: 'CaseCheckNoPass',
        component: () => import("@/views/caseCheck/CaseCheckNoPass.vue"),
      }, {
        path: 'lawsAndRegulations',
        name: 'LawsAndRegulations',
        component: () => import("@/views/datadic/LawsAndRegulations"),
      }, {
        path: 'term',
        name: 'Term',
        component: () => import("@/views/datadic/Term"),
      }, {
        path: 'laws',
        name: 'Laws',
        component: () => import("@/views/datadic/Laws"),
      }, {
        path: 'account',
        name: 'Account',
        component: () => import("@/views/jurisdiction/Account"),
      }, {
        path: 'problemNotification',
        name: 'ProblemNotification',
        component: () => import("@/views/fiveBag/ProblemNotification"),
      }, {
        path: 'frontFiveBags',
        name: 'FrontFiveBags',
        component: () => import("@/views/fiveBag/FrontFiveBags"),
      }, {
        path: 'template',
        name: 'Template',
        component: () => import("@/views/modelappy/Template"),
      }, {
        path: 'place',
        name: 'Place',
        component: () => import("@/views/jurisdiction/Place"),
      }, {
        path: 'operateRecord',
        name: 'operateRecord',
        component: () => import("@/views/modelappy/OperateRecord"),
      }, {
        path: 'boothLicence',
        name: 'BoothLicence',
        component: () => import("@/views/licence/BoothLicence.vue"),
      }, {
        path: 'placeType',
        name: 'PlaceType',
        component: () => import("@/views/jurisdiction/PlaceType"),
      },
      {
        path: '/caseLeaderNoApproval',
        name: 'CaseLeaderNoApproval',
        component: () => import("@/views/administrativeCommittee/CaseLeaderNoApproval.vue"),
      },
      {
        path: '/caseLeaderApprovalNoPass',
        name: 'CaseLeaderApprovalNoPass',
        component: () => import("@/views/administrativeCommittee/CaseLeaderApprovalNoPass.vue"),
      },
      {
        path: '/caseLawNoAuditor',
        name: 'CaseLawNoAuditor',
        component: () => import("@/views/administrativeCommittee/CaseLawNoAuditor.vue"),
      },
      {
        path: '/caseLawAuditorNoPass',
        name: 'CaseLawAuditorNoPass',
        component: () => import("@/views/administrativeCommittee/CaseLawAuditorNoPass.vue"),
      },
      {
        path: '/roleMenu',
        name: 'RoleMenu',
        component: () => import('@/views/permission/RoleMenu.vue')
      },
      {
        path: '/unitMenu',
        name: 'UnitMenu',
        component: () => import('@/views/permission/UnitMenu.vue')
      },
      {
        path: '/stallUser',
        name: 'StallUser',
        component: () => import('@/views/licence/StallUser.vue')
      },
      {
        path: '/stall',
        name: 'Stall',
        component: () => import('@/views/licence/Stall.vue')
      }
    ]
  },
  {
    path: '/after',
    name: 'After',
    component: () => import('../views/After.vue')
  },
  {
    path: '/black',
    name: 'Black',
    component: () => import('../views/Black.vue')
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('../views/Login')
  },
  {
    path: '/signTemblate',
    name: 'SignTemblate',
    component: () => import('../views/SignTemblate.vue')
  },
  {
    path: '/test',
    name: 'Test',
    component: () => import('../views/Test.vue')
  },

];

const option = [
  'whiteBoard', '202308111111', '202308222222', '202308333333', '202308444444', '202306041054',
  '202306051054', '202306061054', '202306071054', '202306091054', '202306111054', '202306121054',
  '202306131054', '202306141054', '202306151054', '202307051741', '202307131234', '202307131235',
  '202307171234', '202307180000', '202307180001', '202307180002', '202307180003', '202307180004',
  '202307180005', '202307180006', '202307180007', '202307180008', '202307181234', '202307191234',
  '202307201234', '20230718125', '202307211234', '202307211235', '202307241234', '202307241235',
  '202307241236', '202307241237', '202307241238', '202308020919', '202308021710', '202308041331',
  '202309784301', '202309784304', '202309784305', '202309784306', '202309784307', '202508271709',
  '202309784309', '202309784402', '202309784404', '202309784405', '202309784406', '202309784407',
  '202309784408', '202309784502', '202306031054', '202306021054', '202306011054', '202307071234',
  '202307081234', '202307091234', '202307101234', '202307111234', '202308011234', '202308021234',
  '202308041234', '202308071234', '202308091234', '202308000001', '202308000003', '202308000004',
  '202308000005', '202308000006', '202308000007', '202308000008', '202308000009', '202308000010',
  '202308000012', '202307180009', '202307180010', '202307180011', '202307180012', '202307201235',
  '202308051234', '202308061234', '202306201054', '202307180110', '202307180112', '202406251026',
  '202405301436', '202507251641', '202507251642', '202507251643', '202507251644', '202507251645',
  '202507251646', '202509101433', '202509101534', '202509111537', '202509111622', '202509111624',
  '202509120916', '202507251647',];

option.forEach(item => {
  routes.push({
    path: `/${item}`,
    name: item,
    component: () => import(`../views/template/${item}.vue`)
  });
});

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
});


document.title = "数字综合执法平台";

export default router;

router.beforeEach((to, from, next) => {
  if (to.path === '/login' || to.path === '/black' || to.path === '/after') {
    next();
    return;
  }
  //如果访问的是文书路径，则放行
  if (option.includes(to.path.substring(1))) {
    next();
    return;
  }
  if (to.path.includes("PDF")) {
    next();
    return;
  }
  let user = localStorage.getItem("user") ? JSON.parse(localStorage.getItem("user")) : {}
  const userMenus = user.menus || []
  if (!userMenus.find(p => p.path === "home")) {
    ElMessage.error("您没有权限访问，请联系管理员！")
    next('/login')
  } else if (!userMenus.find(p => "/" + p.path === to.path)) {
    next('/black')
  } else {
    next()
  }
})

